package com.jh.complicate.serializable;

import java.io.Serializable;

/**
 * @author Administrator
 * @projectName newforward
 * @title User.java
 * @package com.jh.complicate.serializable
 * @description 用户类
 * @date 2019/6/4 18:11
 */
public class User implements Serializable {

    private static final long serialVersionUID = 7146621086766299472L;

    /**
     * 只有Java原生的序列化和反序列化支持通过readObject和writeObject方法进行绕过Transient修饰符
     */
    //private transient String name;
    private String name;
    private Integer age;

    /**
     * 依旧序列化name属性的话要加这两个方法
     */
    private void readObject(java.io.ObjectInputStream s)
            throws java.io.IOException, ClassNotFoundException {
        s.defaultReadObject();
        name = (String) s.readObject();
    }

    private void writeObject(java.io.ObjectOutputStream s)
            throws java.io.IOException {
        s.defaultWriteObject();
        s.writeObject(name);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User[age：" + age + ", name：" + name + "]";
    }

}
